package two.chapter_1.c1_5;

public class PathCompressWeightedQuickUnionUF extends WeightedQuickUnionUF {
    public PathCompressWeightedQuickUnionUF(int N) {
        super(N);
    }

    public int find(int p) {
        int root = p;
        while (root != ids[root])
            root = ids[root];

        while (p != root) {
            int newp = ids[p];
            ids[p] = root;
            p = newp;
        }
        return root;
    }
}
